package com.neu.niuyuchao.servlet;

import com.neu.niuyuchao.service.StuInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AllrutBatchStuServlet", urlPatterns = {"/AllrutBatchStuServlet.do"})
public class AllrutBatchStuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String[] key=request.getParameterValues("approveBox");


        String[]k=new String[key.length];
        for (int i = 0; i <key.length ; i++) {
            System.out.println(key[i]);
            String  ke= key[i].substring(key[i].lastIndexOf(",")+1);
            k[i]=ke;
        }
        StuInfoService s=new StuInfoService();
        boolean flag=s.Allrut(k);
        if (flag){
            response.sendRedirect(request.getContextPath()+"/commons/success.jsp");
        }else {
            response.sendRedirect(request.getContextPath()+"/commons/fail.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
